<?php
namespace Textblast;

require_once 'util/validate.php';
require_once 'user.php';

session_start();
if(isset($_SESSION['User_Session'])) {
	header("Location: index.php");
}

if($_SERVER["REQUEST_METHOD"] == "POST") {

	$username=addslashes($_POST['username']); 
	$password=addslashes($_POST['password']); 

	$user = new User();

	if(Validate::isUsername($username) && ( $det =
	   $user->isMember($username, $password)) == true) {
		$_SESSION['User_Session'] = $det[1][0];
		session_write_close();
		header("Location: index.php");
	} else {
        echo 'Username or password incorrect!';
	}
}
?>
<html>
<head>
	<title>Textblast | Login</title>
	<style type="text/css">
		body {
			margin: 0px;
			padding: 0px;
			font-size: 10pt;
			font-family: verdana,helvetica,arial,sans-serif;
			background: #EAEAEA;
		}
		div {
			display: block;
		}
		.loginHeader{
			height: 40px;
		}
		.loginBody {
			border-color: gray;
			border-width: 1;
			border-style: solid;
			/*background-color: CadetBlue;*/
			color: white;
		}
		#registerPanel {
			display: inline-block;
			height: 400px;
			width: 600px;
			margin: 20px;
			border-radius: 10;
			border-color: gray;
			border-width: 1;
			border-style: solid;
		}
		#loginPanel {
			display: inline-block;
		}
	</style>
</head>
<body>

<!--<?php 
	/*include('connect.php');
	session_start();
	$user_check = $_SESSION['userlogin'];
	if(isset($user_check)) {
		header("Location: index.php");
	}

	if($_SERVER["REQUEST_METHOD"] == "POST") {
		$myusername=addslashes($_POST['username']); 
		$mypassword=addslashes($_POST['password']); 

		$sql="SELECT userid FROM users WHERE username='$myusername' and password=SHA2('$mypassword',0)";
		$result=mysql_query($sql);
		$count=mysql_num_rows($result);
		if($count == 1) {
			//session_register("myusername");
			$_SESSION['userlogin']=$myusername;
			header("location: index.php");
		}
	}

	//include('disconnect.php');
	mysql_close($con);*/
?>-->
<div class='loginHeader'></div>
<div class='loginBody'>
	<span>Sign Up for free!</span>
</div>
<div id='registerPanel' style='display:none;'>
	<form action="register.php" method="post">
		<table>
			<tr>
				<td>Organization:</td>
				<td><input type='textbox' name='OrgName'/></td>
			</tr>
			<tr>
				<td>Username:</td>
				<td><input type='textbox' name='UserName'/></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type='password' name='Password'/></td>
			</tr>
			<tr>
				<td>Repeat Password:</td>
				<td><input type='password' /></td>
			</tr>
			<tr>
				<td>Email:</td>
				<td><input type='textbox' name='Email'/></td>
			</tr>
			<tr>
				<td></td>
				<td><input type='submit' value='Register' /></td>
			</tr>
		</table>
	</form>
</div>
<div id='loginPanel'>
	<form action="" method="post">
		<table>
			<tr>
				<td>User:</td>
				<td><input type='textbox' name='username'/></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type='password' name='password'/></td>
			</tr>
			<tr>
				<td></td>
				<td><input type='submit' value='Login' /></td>
			</tr>
		</table>
	</form>
</div>
</body>
</html>